﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using RZD_maps.Modules.Properties.Views;
using RZD_maps.Infrastructure;
using Microsoft.Practices.Prism.Events;


namespace RZD_maps.Modules.Properties.ViewModels
{
    public class ViewModel
    {
        private IView view;

        private IEventAggregator eventAggregator;
        private SubscriptionToken subscriptionToken;

        public ViewModel()
        {
        }

        public ViewModel(IEventAggregator eventAggregator) : this()
        {
            this.eventAggregator = eventAggregator;
            SubscriptCommands();
        }

        public void SubscriptCommands()
        {
            InfoForGraphicsEvent evnt = eventAggregator.GetEvent<InfoForGraphicsEvent>();

            if (subscriptionToken != null)
            {
                evnt.Unsubscribe(subscriptionToken);
            }

            subscriptionToken = evnt.Subscribe(InfoForGraphicsEventHandler, ThreadOption.UIThread, false, InfoForGraphicsFilter);
        }

        public bool InfoForGraphicsFilter(InfoForGraphics data)
        {
            return true;
        }

        public void InfoForGraphicsEventHandler(InfoForGraphics item)
        {
            ((View)View).paramsData.Text=item.name;
        }

        public IView View
        {
            get { return view; }
            set
            {
                view = value;
            }
        }


    }
}
